package com.demo2do.fms.admin.entity.search.supplier;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.demo2do.fms.entity.vehicle.VehicleStatus;
import com.demo2do.fms.entity.vehicle.source.LockStatus;

/**
 *
 * @author houtao
 *
 */
public class AbnormalCapacitySearch implements QueryBuilder {
    
    /** 所属供方 */
    private Long supplierId;
    
    /** 所属供方代码 */
    private String supplierCode;
    
    /** 所属供方名称 */
    private String supplierName;
    
    /** 操作记录 */
    private LockStatus status;
    
    /** 牵引车车牌号 */
    private String tractorBrandCode;
    
    /** 锁车原因 */
    private String lockReason;
    
    /** 车辆状态 */
    private VehicleStatus vehicleStatus;
    
    private QueryOrder queryOrder;

    private QueryFilter queryFilter;

    /**
     * The default constructor
     */
    public AbnormalCapacitySearch() {
        queryOrder = new QueryOrder("createTime", "DESC");
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if (queryFilter == null || refresh) {

            queryFilter = new QueryFilter().addEquals("status", status)
            							   .addEquals("vehicleSource.supplier.id", supplierId)
            							   .addEquals("vehicleSource.supplier.code", supplierCode)
            							   .addLike("vehicleSource.supplier.name", supplierName)
            							   .addLike("vehicleSource.tractorBrandCode", tractorBrandCode)
                                           .addEquals("vehicleSource.lockReason", lockReason)
                                           .addEquals("vehicleSource.vehicleStatus", vehicleStatus)
                                           .addEquals("vehicleSource.disabled", false);
            
        }
        
        return queryFilter;
        
    }
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return queryOrder;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM VehicleSourceLockRecord" + getPreparedFilter(false).whereSentence() + queryOrder.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /**
     * 
     * @return
     */
    public QueryFilter getFilter(){
        return getPreparedFilter(false);
    }

    /**
     * @return
     */
    public Long getSupplierId() {
		return supplierId;
	}
    
    /**
     * @return
     */
    public String getSupplierCode() {
		return supplierCode;
	}

    /**
     * @return
     */
    public String getSupplierName() {
		return supplierName;
	}

    /**
     * @return the status
     */
    public LockStatus getStatus() {
        return status;
    }
    
    /**
     * @return
     */
    public String getTractorBrandCode() {
		return tractorBrandCode;
	}

    /**
     * @return the lockReason
     */
    public String getLockReason() {
        return lockReason;
    }

    /**
     * @return the vehicleStatus
     */
    public VehicleStatus getVehicleStatus() {
        return vehicleStatus;
    }

    /**
     * @param supplierId
     */
    public void setSupplierId(Long supplierId) {
		this.supplierId = supplierId;
	}
    
    /**
     * @param supplierCode
     */
    public void setSupplierCode(String supplierCode) {
		this.supplierCode = supplierCode;
	}
    
    /**
     * @param supplierName
     */
    public void setSupplierName(String supplierName) {
		this.supplierName = supplierName;
	}

    /**
     * @param status the status to set
     */
    public void setStatus(LockStatus status) {
        this.status = status;
    }
    
    /**
     * @param tractorBrandCode
     */
    public void setTractorBrandCode(String tractorBrandCode) {
		this.tractorBrandCode = tractorBrandCode;
	}

    /**
     * @param lockReason the lockReason to set
     */
    public void setLockReason(String lockReason) {
        this.lockReason = lockReason;
    }

    /**
     * @param vehicleStatus the vehicleStatus to set
     */
    public void setVehicleStatus(VehicleStatus vehicleStatus) {
        this.vehicleStatus = vehicleStatus;
    }
    
}